﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sunny.Controls
{
	public class BooleanSearchItem : SearchItem
	{
		private BooleanSelector _SimpleSearcherInput;
		public override System.Windows.FrameworkElement SimpleSearcherInput
		{
			get
			{
				if (this._SimpleSearcherInput == null)
					this._SimpleSearcherInput = new BooleanSelector { AllowNull = true, SelectedIndex = 0 };
				return this._SimpleSearcherInput;
			}
		}

		private Operator[] _OperatorOptions;
		public override Operator[] Operators
		{
			get
			{
				if (this._OperatorOptions == null)
					this._OperatorOptions = new Operator[]
					{
						new Operator("=","{0}={1}"),
						new Operator("≠","{0}!={1}")
					};
				return this._OperatorOptions;
			}
		}

		public override System.Windows.FrameworkElement AdvanceSearcherInput
		{
			get
			{
				return new BooleanSelector();
			}
		}

		public override Searcher.WhereCommand GetCommand(string field, int index)
		{
			if (this._SimpleSearcherInput == null)
				return null;
			if (this._SimpleSearcherInput.SelectedBoolean == null)
				return null;
			return new Searcher.WhereCommand { Text = string.Format("{0}==@{1}", field, index), Parameters = new object[] { this._SimpleSearcherInput.SelectedBoolean } };
		}

		public override void Empty()
		{
			if (this._SimpleSearcherInput != null)
				this._SimpleSearcherInput.Text = "";
		}
	}
}